// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "ClassFactory.h"


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		g_hModule = hModule;
		break;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

STDAPI DllGetClassObject(__in REFCLSID rclsid, __in REFIID riid, __deref_out LPVOID FAR* ppv)
{
	TraceMsg(L"DllGetClassObject\n");
	CClassFactory *pClassFactory = new CClassFactory();
	if (pClassFactory)
	{
		pClassFactory->QueryInterface(riid, ppv);
// 		pClassFactory->Release();
		return S_OK;
	}
	else
	{
		return E_OUTOFMEMORY;
	}
	return E_NOINTERFACE;
}

STDAPI DllCanUnloadNow()
{
	TraceMsg(L"DllCanUnloadNow");
	return CClassFactory::CheckCanUnload();
// 	return S_FALSE;
}

STDAPI DllRegisterServer(void)
{
	TraceMsg(L"DllRegisterServer");
	wchar_t wszDllFilePath[MAX_PATH];
	memset(wszDllFilePath, 0, sizeof(wchar_t)*MAX_PATH);
	::GetModuleFileName(g_hModule, wszDllFilePath, MAX_PATH);
	RegistCom(CLSID_Math, wszDllFilePath, L"GSE.Math.1.0");
	return S_OK;
}

STDAPI DllUnregisterServer(void)
{
	TraceMsg(L"DllUnregisterServer");
	UnRegistCom(CLSID_Math);
	return S_OK;
}
